#include "server_start.h"

gint delete_event(GtkWidget *window){
	gtk_main_quit();
	return FALSE;
}
int main(int argc, char *argv[]){
	GtkWidget *window;
	gtk_init(&argc, &argv);
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);  
	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
	gtk_window_set_title(GTK_WINDOW(window), "calou server");
	g_signal_connect(G_OBJECT(window), "delete_event",G_CALLBACK(delete_event), NULL);

	gtk_container_set_border_width(GTK_CONTAINER(window), 10);
	
	display_window(window);
	gtk_widget_show_all(window);

	if(!pthread_socket_start()){
		g_printf("socket start sucess! \n");
	}
	gtk_main();
	return 0;
}

void *display_window(GtkWidget *window){
	GtkWidget *table;
	GtkWidget *noteBook;
	GtkWidget *frame;
	GtkWidget *label;
	GtkWidget *scrolled_window;
	int i = 0;
	char buffer[2][32] = {"用户信息","登录监控情况"};
	table = gtk_table_new(1, 2, FALSE);
	gtk_container_add(GTK_CONTAINER(window), table);

	noteBook = gtk_notebook_new();
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(noteBook), GTK_POS_TOP);
	gtk_table_attach_defaults(GTK_TABLE(table), noteBook, 0, 1, 0, 2);
	for(i = 0; i < 2; i++){
		frame = gtk_frame_new(NULL);
		gtk_container_set_border_width(GTK_CONTAINER(frame), 10);
		gtk_widget_set_size_request(frame, 500,400);
		scrolled_window = gtk_scrolled_window_new(NULL, NULL);
		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
		if(i == 1){
			GtkWidget *text_view;
			text_view = gtk_text_view_new();
			GtkTextBuffer *buf;
			GtkTextIter iter;
			buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
			gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), text_view);
			gtk_text_view_set_editable(GTK_TEXT_VIEW(text_view), FALSE);
		}

		gtk_container_add(GTK_CONTAINER(frame), scrolled_window);

		label = gtk_label_new(buffer[i]);
		gtk_notebook_append_page(GTK_NOTEBOOK(noteBook), frame, label);
	}

}
